import { config } from '../../config';
import { sequelize } from '../db';
import { Model, DataTypes } from 'sequelize';
class Menu extends Model {
    declare img: string
    declare upLevel: string
    declare label: string
    declare url: string
    declare icon: string
    declare imgUrl: string
    declare type: number
    declare public: number
    declare isPhone: number
    declare state: boolean
    declare sub: any[];
}

Menu.init({
    label: DataTypes.STRING,
    url: DataTypes.STRING,
    icon: DataTypes.STRING,
    img: DataTypes.STRING,
    imgUrl: {
        type: DataTypes.VIRTUAL,
        get() {
            return this.img && this.img.match(/^\//) ? config.BASEURL + this.img : this.img
        },
        set(value) {
            throw new Error('不要尝试设置 `imgUrl` 的值!');
        }
    },
    upLevel: DataTypes.STRING,
    type: DataTypes.INTEGER,
    public: DataTypes.INTEGER,
    isPhone: {
        type: DataTypes.INTEGER,
        defaultValue: 0
    },
    state: {
        type: DataTypes.BOOLEAN,
        defaultValue: true
    }
}, {
    sequelize
});

export default Menu